<?php
//------------------------------------------------------------------------------
// File               : V_SanphamList
// Modification       :
//------------------------------------------------------------------------------
// Date(yyyy.mm.dd)   Developer                       Action
//------------------------------------------------------------------------------
// 2007.03.15         Oanhhtk                         Created
//------------------------------------------------------------------------------

function V_SanphamList(&$arrayData,$action,$arrayData_catSanpham){
	global $LANG,$db;
    $ulr = "?".MODUL."=sanpham&".ACTION."=";
	$parent_id = CM_getParameter("parent_id");
	$cat_id = CM_getParameter("id_loai_sp");
	include_once(DIR_MODEL."md_cat_san_pham.class.php");
	$objcatSanpham = new MD_CatSanpham($db);
	$arrayData_catSanpham2 =  array();      
	$arrayData_catSanpham2 = $objcatSanpham->getById2($cat_id);	
	$CatName = $arrayData_catSanpham2['ten_loai_sp'];
	//hang sx
	include_once(DIR_MODEL."md_hang_sx.class.php");
	$objHangsx = new MD_Hangsx($db);


?>
<div id="sortdiv">
<?
	//CM_showError();
	//phan trang
	$totalRows = 0;
	$curPage =1;
	$strStart =0;
	$strEnd=0;
	$totalRecord = NUM_ROW_SP;
	
	$totalRows=count($arrayData);

	$curPage =CM_getParameter("curPg");
	if(((int)$curPage)==0) $curPage =1;
	
	$totalPage = 	(int)($totalRows/ $totalRecord);
	if($totalRows % $totalRecord > 0 ) $totalPage ++;
	
	if($totalRows >0){
		$strStart = ($curPage -1) * $totalRecord +1;
		$strEnd   = ($curPage )   * $totalRecord ;
		if($strEnd  > $totalRows ) $strEnd  = $totalRows;
	}
	$tong = sizeof($arrayData);
?>
<script>
function GotoPage(iPage) 
{
	document.frmContent.curPg.value = iPage;	
	var sapxep = document.getElementById("sortList2").value;
	if(sapxep==""){
		sapxep = "desc";
	}
	document.frmContent.action = "../run/main.php?modul=sanpham&action=List&id_loai_sp=<?=$cat_id?>&parent_id=<?=$parent_id?>&sort="+sapxep+"&curPage="+iPage;
	document.frmContent.submit();
}
</script>

<form action="" name="frmContent" method="post">
<input type="hidden" name="id_loai_sp" value="<?=$_POST['id_loai_sp']?>">
<input type="hidden" name="parent_id" value="<?=$_POST['parent_id']?>">
<input type="hidden" name="sortList2" value="" id="sortList2">
<div class="title" style="margin-left:10px; width:10px; height:30px; float:left;">
	
</div><!-- title -->
<p style="float:left; line-height:30px; font-weight:bold; color:#FFFFFF; background: url(../images/modul_c.gif);"><? echo $CatName;?></p>
<div class="title2" style="width:10px; height:30px; float:left"></div>

<div style="clear:both;" class="clear_ie"></div>
<div class="bg_l_t"><div class="bg_r_t"><div class="bg_c_t"></div></div></div>
<div class="cat_sp_cen">

<?
if($totalRows>0){
	$curRow=0;
	$i=0;
	
?>
<table  width="100%" cellpadding="0" cellspacing="0">
<?
	foreach($arrayData as $row){
		
		$curRow ++;
		if( $curRow < $strStart ) continue;
		if( $curRow > $strEnd )  break;
		$i+1;
		$Money = to_money($row['gia_sp']); 
		$money_detail = "$Money VNĐ";
		$text = "<table width='300' cellpadding='0' cellspacing='0'><tr><td>".$row['mo_ta_sp']."</td></tr></table>";
?>
	<tr style="height:120px;">
		<td width="123" align="center">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td align="center" style="padding-bottom:3px; ">
					<?
					$arrayDataHangsx = $objHangsx -> getById($row['hang_sx']);
					if(!empty($arrayDataHangsx['ten_anh'])){
						$exists_hsx = file_exists(DIR_IMAGES_VIEW_HANG_SX.$arrayDataHangsx["ten_anh"]);
						if($exists_hsx){
					?>
					<img src="<?=DIR_IMAGES_VIEW_HANG_SX.$arrayDataHangsx['ten_anh']?>" width="81" />
					<?
						}
					}
					?>
					</td>
				</tr>
				<tr>
					<td style="border:1px solid #E9AE95; border-collapse:collapse;" align="center">
						<a href="?modul=sanpham&action=View&parent_id=<?=$parent_id?>&id_loai_sp=<?=$row['id_loai_sp']?>&id=<?=$row['id']?>">
						<?
						if(!empty($row['anh_sp'])){
							$exists = file_exists(DIR_IMAGES_VIEW.$row["anh_sp"]);
							if($exists){
						?>
						<img src="<?=DIR_IMAGES_VIEW.$row['anh_sp']?>" width="100" border="0" height="100" title="cssheader=[boxover-cssheader] cssbody=[boxover-cssbody] header=[<?=$row['ten_sp']?>] body=[<?=$text?>]" />
						<?
							}else{
						?>
						<img src="../images/no_image_130.jpg"  class="image_thumb_news" width="100" border="0" height="100" title="cssheader=[boxover-cssheader] cssbody=[boxover-cssbody] header=[<?=$row['ten_sp']?>] body=[<?=$text?>]"/>
						<?
							}
						?>
						<?
						}else{
						?>
						<img src="../images/no_image_130.jpg"  class="image_thumb_news" width="100" border="0" height="100" title="cssheader=[boxover-cssheader] cssbody=[boxover-cssbody] header=[<?=$row['ten_sp']?>] body=[<?=$text?>]"/>
						<?
						}
						?>
						
						</a>
					</td>
				</tr>
			</table>		
		</td>
		<td width="647" valign="top" style="padding-right:5px; padding-top:3px; padding-left:20px;  " >
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td class="cat_ten_sp" style="line-height:20px;">
						<a href="?modul=sanpham&action=View&parent_id=<?=$parent_id?>&id_loai_sp=<?=$row['id_loai_sp']?>&id=<?=$row['id']?>">
						<span style="text-transform:uppercase; color:#007DEB;"><?=$row['ten_sp']?></span>
						</a>
					</td>
				</tr>
				<tr>
					<td style="line-height:20px; ">
						<?=$row['mo_ta_sp']?>
					</td>
				</tr>
			</table>		
		</td>
		<td width="200">
		<?
		if($row['gia_sp_km']>0){
		?>
		<span class="ten_gia">Giá cũ:&nbsp;&nbsp;</span><span class="gia_cu"><?=to_money($row['gia_sp'])?> VNĐ</span><br>
		<span class="ten_gia">Chỉ còn:&nbsp;</span><span class="gia_moi"><?=to_money($row['gia_sp_km'])?> VNĐ</span><br><br>
		<?
		}else{
		?>
		<span class="ten_gia">Giá sản phẩm:</span><br /><span class="gia_moi"><?=$money_detail?></span><br /><br />
		<?
		}
		?>
		<span class="muangay">
		<a href="?modul=giohang&action=View&id=<?=$row["id"]?>">Mua ngay</a>
		</span><br />
		<span class="chitiet_sp">
		<a href="?modul=sanpham&action=View&parent_id=<?=$parent_id?>&id_loai_sp=<?=$row['id_loai_sp']?>&id=<?=$row['id']?>">Chi tiết</a>
		</span>
		</td>
	</tr>
<?
		$tong--;
		//if ($tong){
		if( $curRow < $strEnd ){
?>
	<tr><td colspan="3"><hr style="border-bottom:0.1em solid #FF0000;" /></td></tr>
<?
		}
		
	}//end foreach
?>
	<tr>
		<td colspan="3" style="padding-top:20px; ">
			<?
			if($totalPage>1){	
			?>
			<table  cellpadding="0" cellspacing="0" align="center">
				<br>
				<tr>
					<td class="pagingIntact">
						<a href="javascript:GotoPage('1')">&nbsp;&laquo;&nbsp;Trang đầu&nbsp;</a>
					</td>
					<td class="pagingSpace"></td>
					<?
					for($i=1;$i<= $totalPage;$i++){
						if($i < $curPage + 11 && $i > $curPage - 11){
							if($i == $curPage){
					?>
					<td class="pagingViewed">
						<?=$i?>
					</td>
					<td class="pagingSpace"></td>
					<?
							}
							if($i != $curPage){
					?>
					<td class="pagingIntact">
						<a href="javascript:GotoPage('<?=$i?>')"><?=$i?></a>
					</td>
					<td class="pagingSpace"></td>
					<?
							}
						} 
					}
					?>
					<td class="pagingIntact">
						<a href="javascript:GotoPage('<?=$totalPage?>')">&nbsp;Trang cuối&nbsp;&raquo;&nbsp;</a>
					</td>
				</tr>
			</table>
			<?
			}//end if($totalPage>1)
			?>
		</td>
	</tr>
</table>
<?
}//endif
else{
?>
<table  width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td>
			Không có sản phẩm nào.
		</td>
	</tr>
</table>
<?
}//end else

?>
</div><!-- cat_sp_cen -->

<div class="bg_l_b"><div class="bg_r_b"><div class="bg_c_b"></div></div></div>
<input type="hidden"  name="curPg"  value="0" >
<input type="hidden"  name="id"  value="<?=CM_getParameter('id')?>" >
<input type="hidden"  name="textfield"  value="<?=CM_getParameter('textfield')?>" >
</form>
</div>
<?
	foreach ($_POST as $key => $value) {
		$value = htmlspecialchars( CM_getParameter($key));
		echo '<input type=hidden  name="'.$key.'"  value="'.$value.'" >';
		echo "\n";
	}
}
?>

